﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorkTime.Logical
{
    /// <summary>
    /// 工作日帮助类
    /// </summary>
    public static class WorkingDateUtil
    {
        private static Dictionary<DateTime, bool> cache = new Dictionary<DateTime, bool>();

        private static object syncRoot = new object();
        /// <summary>
        /// 判断某个日期是否为工作日
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static bool IsWorkingDay(DateTime date)
        {
            bool flag;
            if (!cache.TryGetValue(date, out flag))
            {
                //TODO:access db to obtain vale here flag = ......

                lock (syncRoot)
                {
                    cache[date] = flag;
                }
            }
            return flag;
        }

        /// <summary>
        /// 刷新缓存
        /// </summary>
        public static void Refresh()
        {
            lock (syncRoot)
            {
                cache.Clear();
            }
        }
    }
}
